use std::net::TcpStream;
use std::io::Write;
use std::io::Read;
use std::io;

fn main() {
    let mut sk = TcpStream::connect("127.0.0.1:34254")
    .expect("cannot connect to server");
    //let mut arr:[u8;128];
    sk.write(&[1]);
    //stream.read(&mut [0,128])?;
    //let mut buf = vec![];
    let mut buf = String::new();
    loop {
        match sk.read_to_string(&mut buf) {
        Ok(_) => break,
        Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
            // wait until network socket is ready, typically implemented
            // via platform-specific APIs such as epoll or IOCP
            //wait_for_fd();
        }
        Err(e) => panic!("encountered IO error: {}", e),
        };
    };
    println!("bytes: {:?}", buf);
} // the stream is closed here
